package com.hejun.bos.action.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import com.hejun.bos.common.base.BaseAction;
import com.hejun.bos.domain.base.Standard;
import com.hejun.bos.service.base.StandardService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Namespace("/standard")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
public class StandardAction extends BaseAction<Standard> {
	private static final long serialVersionUID = 1L;

	@Autowired
	private StandardService standardService;

	@Action(value = "standardSave", results = {
			@Result(name = "success", type = "redirect", location = "/pages/base/standard.html") })
	public String save() {
		standardService.save(model);
		return SUCCESS;
	}

	@Action(value = "findByPage", results = { @Result(name = "success", type = "json") })
	public String findByPage() {
		Pageable pageable = new PageRequest(page - 1, rows);
		Page<Standard> result = standardService.findAll(pageable);
		changeResultToJson(result);
		return SUCCESS;
	}

	@Action(value = "findAll", results = { @Result(name = "success", type = "json") })
	public String findAll() {
		List<Standard> list = standardService.findAll();
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}
}
